package com.itboye.mengwu.app.adapter;

import java.util.ArrayList;

import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.ZengBean;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.Bitmap.Config;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ZengAdapter extends BaseAdapter {

	ArrayList<ZengBean> list;
	Context context;

	public ZengAdapter(ArrayList<ZengBean> list, Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int postion) {
		// TODO Auto-generated method stub
		return postion;
	}

	@Override
	public long getItemId(int postion) {
		// TODO Auto-generated method stub
		return postion;
	}

	@Override
	public View getView(int postion, View con, ViewGroup arg2) {
		// TODO Auto-generated method stub
		HanderViewAdd viewAdd;
		if (con == null) {
			viewAdd = new HanderViewAdd();
			con = LayoutInflater.from(context).inflate(
					R.layout.item_zengwuxian, null);
			viewAdd.title = (TextView) con.findViewById(R.id.txt_title);
			viewAdd.time = (TextView) con.findViewById(R.id.txt_itemTime);
			viewAdd.delete = (ImageView) con.findViewById(R.id.imgZeng);
			viewAdd.img1 = (ImageView) con.findViewById(R.id.imgOne);
			viewAdd.img2 = (ImageView) con.findViewById(R.id.imgTwo);
			viewAdd.img3 = (ImageView) con.findViewById(R.id.imgThree);
			con.setTag(viewAdd);
		} else {
			viewAdd = (HanderViewAdd) con.getTag();

		}
		viewAdd.time.setText(list.get(postion).getTitle());
		viewAdd.time.setText(list.get(postion).getTime());
		ZengBean bean = list.get(postion);
		// 使用ImageLoader加载网络图片
		DisplayImageOptions options = new DisplayImageOptions.Builder()//
				.showImageOnLoading(R.drawable.p1) // 加载中显示的默认图片
				.showImageOnFail(R.drawable.p1) // 设置加载失败的默认图片
				.cacheInMemory(true) // 内存缓存
				.cacheOnDisk(true) // sdcard缓存
				.bitmapConfig(Config.RGB_565)// 设置最低配置
				.build();//
		ImageLoader.getInstance().displayImage(list.get(postion).getImg(),
				viewAdd.img1, options);
		ImageLoader.getInstance().displayImage(list.get(postion).getImge(),
				viewAdd.img2, options);
		ImageLoader.getInstance().displayImage(list.get(postion).getImgw(),
				viewAdd.img3, options);

		return con;
	}

	class HanderViewAdd {
		private TextView title;
		private TextView time;
		// private TextView delete;
		private ImageView img1, img2, img3, delete;

	}

}
